use crate::utils::encrypt_util::get_signature;
use crate::utils::http_util::handle_http;
use crate::utils::service_config::ServiceConfig;
use log::{error, info};
use reqwest::Response;
use serde_json::{json, Value};
use std::future::Future;
use std::time::Duration;
use tokio::runtime::Runtime;

async fn handle_success(response: Response) -> () {
    let response_json: Value = response.json().await.unwrap();
    if response_json["code"] == 0 {
        info!("发送成功,请在手机查看验证码")
    } else {
        error!("{}", response_json["msg"])
    }
}

fn handle_failed(_: Response) {
    error!("获取验证码失败")
}

pub fn captcha(phone: String) {
    let mut post_json = get_signature();
    post_json["phone"] = json!(phone);
    match handle_http(
        "maview".to_string(),
        "loginCode".to_string(),
        post_json,
        handle_success,
        handle_failed,
    ) {
        Ok(_) => {}
        Err(e) => error!("获取验证码失败，{}", e),
    }
}
